package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.SlGrade;
import com.ruoyi.sl.service.ISlGradeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职称Controller
 * 
 * @author admin
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/sl/grade")
public class SlGradeController extends BaseController
{
    @Autowired
    private ISlGradeService slGradeService;

    /**
     * 查询职称列表
     */
    @PreAuthorize("@ss.hasPermi('sl:grade:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlGrade slGrade)
    {
        startPage();
        List<SlGrade> list = slGradeService.selectSlGradeList(slGrade);
        return getDataTable(list);
    }

    /**
     * 导出职称列表
     */
    @PreAuthorize("@ss.hasPermi('sl:grade:export')")
    @Log(title = "职称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlGrade slGrade)
    {
        List<SlGrade> list = slGradeService.selectSlGradeList(slGrade);
        ExcelUtil<SlGrade> util = new ExcelUtil<SlGrade>(SlGrade.class);
        util.exportExcel(response, list, "职称数据");
    }

    /**
     * 获取职称详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:grade:query')")
    @GetMapping(value = "/{gradeId}")
    public AjaxResult getInfo(@PathVariable("gradeId") Long gradeId)
    {
        return success(slGradeService.selectSlGradeByGradeId(gradeId));
    }

    /**
     * 新增职称
     */
    @PreAuthorize("@ss.hasPermi('sl:grade:add')")
    @Log(title = "职称", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlGrade slGrade)
    {
        slGrade.setCreateBy(getUsername());
        return toAjax(slGradeService.insertSlGrade(slGrade));
    }

    /**
     * 修改职称
     */
    @PreAuthorize("@ss.hasPermi('sl:grade:edit')")
    @Log(title = "职称", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlGrade slGrade)
    {
        slGrade.setUpdateBy(getUsername());
        return toAjax(slGradeService.updateSlGrade(slGrade));
    }

    /**
     * 删除职称
     */
    @PreAuthorize("@ss.hasPermi('sl:grade:remove')")
    @Log(title = "职称", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gradeIds}")
    public AjaxResult remove(@PathVariable Long[] gradeIds)
    {
        return toAjax(slGradeService.deleteSlGradeByGradeIds(gradeIds));
    }
}
